package com.jdz.gxq.info.admin.logon.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import jp.terasoluna.fw.dao.QueryDAO;

import com.jdz.gxq.info.admin.logon.bo.MenuInfo;
import com.jdz.gxq.info.admin.role.bo.User;

public class LogonServiceImpl implements LogonService {
	
	private QueryDAO queryDAO = null;
	
	public User getUserByName(String name) {
		return queryDAO.executeForObject("logon.getUserByName", name, User.class);
	}
	
	public List<MenuInfo> getMainMenusByRoleId(String roleId) {

		return queryDAO.executeForObjectList("logon.getMainMenusByRoleId", roleId);

	}
	
	public List<MenuInfo> getMenusByRoleId(String roleId) {
		
		// 先得到主菜单
		List<MenuInfo> mainMenuList = queryDAO.executeForObjectList(
				"logon.getMainMenusByRoleId", roleId);

		// 根据主菜单id和权限得到二级菜单
		for (MenuInfo menuInfo : mainMenuList) {
			Map<String, Object> params = new HashMap<String, Object>();
			params.put("roleId", roleId);
			params.put("parentMenuId", menuInfo.getMenuId());
			
			List<MenuInfo> subMenuList = queryDAO.executeForObjectList("logon.getSubMenus", params);
			
			menuInfo.setSubMenuList(subMenuList);	
		}
		
		return mainMenuList;
	}
	
	public void setQueryDAO(QueryDAO queryDAO) {
		this.queryDAO = queryDAO;
	}
	
}
